// pages/service/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollHeight:0,
    screenWidth:0,
    srvCount: 0,
    srvAmount: 0,
    checkedSrv:[],
    csServices:[],
    srvDetails: [],
    details: {
      Guid: "00000000000000000000000000000000",
      HourCost: 0,
      Id: 0,
      Introduction: "",
      Name: "",
      Products: []
    },
    products: {
      CPTId: "",
      Model: "",
      Name: "",
      Price: 0,
      ProductName: ""
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          scrollHeight: res.windowHeight,
          screenWidth: res.windowWidth
        })
      },
    });
    wx.request({
      url: 'https://www.limecar.cn/WxApi/ServiceList',
      data:{ },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        that.setData({
          csServices : res.data
        });
      }
    });
    that.setData({
      checkedSrv: JSON.parse(options.srvs)
    })
  },

  checkOut: function (options){
    let that = this;
    let pages = getCurrentPages();
    let fatherPage = pages[pages.length-2];
    if(that.data.checkedSrv.toString().indexOf(options.target.dataset.srv) < 0){
      fatherPage.setData({
        newSrv: options.target.dataset.srv.toString()
      })
      wx.navigateBack({
        delta: 1
      })
    }else{
      wx.showToast({
        title: '已选择该服务',
        icon: 'none',
        duration: 2200
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})